package com.sh.sales.happysales.app.utils;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;

import com.sh.sales.happysales.app.AppData;
import com.sh.sales.happysales.app.AppManager;
import com.sh.sales.happysales.datautils.LocalTokenUtils;
import com.sh.sales.happysales.datautils.LocalUserInfoUtils;
import com.sh.sales.happysales.ui.activity.LoginActivity;
import com.sh.sales.happysales.view.NewToast;

/**
 * Created by zhouyucheng on 2017/9/30.
 */

public class LoginOutUtil {
    private static boolean isExit = false;


    public static void logOut(Context mConntext) {
        LocalTokenUtils.deleteUserToken("1");
        LocalUserInfoUtils.deleteUserInfoResult("1");
        AppData.getInstence().setmUserInfoResult(null);
        AppData.getInstence().setmUserToken(null);
        Intent login = new Intent();
        login.setClass(mConntext, LoginActivity.class);
        mConntext.startActivity(login);
        AppManager.getAppManager().finishAllActivity();
    }

    private static Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 0:
                    isExit = false;
                    break;
            }
        }
    };

    public static void appDoublebtExit(Context mContext) {
        if (!isExit) {
            isExit = true;
            NewToast.makeText(mContext, "再按一次退出");
            mHandler.sendEmptyMessageDelayed(0, 2000);
        } else {
            AppManager.getAppManager().appExit(mContext);
        }

    }
}
